#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/11/15 下午2:51
# @Author  : yinxin
# @File    : SpiderConfig
# @Software: PyCharm

import inspect
from pathlib import Path

from happy_python import HappyConfigBase

from log import hlog


class SpiderConfig(HappyConfigBase):
    """
    配置文件模板
    """

    spider = {}

    def __init__(self):
        func_name = "MqConfig." + inspect.stack()[0][3]
        hlog.enter_func(func_name)

        super().__init__()

        self.section = "spider_config"
        self.spider_home = ""
        self.spider_dir = ""

        hlog.var("SpiderConfig.section", self.section)

        hlog.exit_func(func_name)

    def load_spider(self):
        func_name = "MqConfig." + inspect.stack()[0][3]
        hlog.enter_func(func_name)

        spider_home_path = Path(self.spider_home)

        group_list = self.spider_dir.split("|")
        for platform in group_list:
            info = platform.split(",")
            self.spider[info[0]] = {
                "list": spider_home_path / Path(info[1]),
                "detail": spider_home_path / Path(info[2])
            }

        hlog.var("SpiderConfig.spider", self.spider)

        hlog.exit_func(func_name)
